package cn.com.org.base;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Basefilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
			FilterChain filterChain) throws IOException, ServletException {
		
	    HttpServletResponse response=(HttpServletResponse)servletResponse;
		HttpServletRequest request=(HttpServletRequest)servletRequest;
		//System.out.println(request.getRequestURI()+"----"+request.getContextPath()+"-----"+request.getContextPath());
		//String uri = request.getRequestURI().replaceFirst(request.getContextPath(),"");	
  //System.out.println("uri====>"+uri);
//		if((userinfo==null||"".equals(userinfo))&&uri.indexOf("/LoginInfo/login")<0){ //if not login,redirect to login page
//		   responseh.sendRedirect(requesth.getContextPath()+"/LoginInfo/login.do");
//			return;
//		}
	/*      if(uri.equals("/")){
	    	  response.sendRedirect(request.getContextPath()+"/home");
	    	  return;
	      }
	    if(uri.indexOf(".")<=0&&!uri.endsWith("/")){
	    	System.out.println("-----------");
		   RequestDispatcher discarder = servletRequest.getRequestDispatcher(uri+ ".do");
		   filterChain.doFilter(servletRequest, servletResponse);// 
			return;
	    } */ 
		
		filterChain.doFilter(servletRequest, servletResponse);// 
		
	}

	@Override
	public void destroy() {
	}

}
